package com.lej.core.widget.customview

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView

class CustomScaleImageView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
    var scale = 0f

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val hms = if (scale == 0f) heightMeasureSpec else MeasureSpec.makeMeasureSpec(
            (MeasureSpec.getSize(widthMeasureSpec) * scale).toInt(),
            MeasureSpec.EXACTLY
        )
        super.onMeasure(widthMeasureSpec, hms)
    }
}